/**
 * Copyright © 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
 */
package com.jeeplus.modules.peopleinformation.basicdata.service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.peopleinformation.basicdata.entity.PeopleInformation;
import com.jeeplus.modules.peopleinformation.basicdata.mapper.PeopleInformationMapper;

/**
 * 人员基础资料Service
 * @author 刘明星
 * @version 2021-03-28
 */
@Service
@Transactional(readOnly = true)
public class PeopleInformationService extends CrudService<PeopleInformationMapper, PeopleInformation> {

	Page<PeopleInformation> page = new Page<>();

	public PeopleInformation get(String id) {
		return super.get(id);
	}
	
	public List<PeopleInformation> findList(PeopleInformation peopleInformation) {
		return super.findList(peopleInformation);
	}
	
	public Page<PeopleInformation> findPage(Page<PeopleInformation> page, PeopleInformation peopleInformation) {

		String oneInstitutional = peopleInformation.getOneInstitutional();//单位
		String administrativeLevel = peopleInformation.getAdministrativeLevel();//行政级别
		String twoInstitutionalName = peopleInformation.getTwoInstitutionalName();//科室名称
		String jobNature = peopleInformation.getJobNature();//岗位性质
		String identity = peopleInformation.getIdentity();//岗位分类
		if(oneInstitutional != null && oneInstitutional.indexOf(",") != -1){
			String[] split = oneInstitutional.split(",");
			ArrayList<String> arrayList = new ArrayList<>();
			Collections.addAll(arrayList, split);
			peopleInformation.setOneInstitutionallist(arrayList);
		}else if(oneInstitutional != null && oneInstitutional.indexOf(",") == -1){
			String[] split = new String[]{oneInstitutional};
			ArrayList<String> arrayList = new ArrayList<>();
			Collections.addAll(arrayList, split);
			peopleInformation.setOneInstitutionallist(arrayList);
		}
		if(administrativeLevel != null && administrativeLevel.indexOf(",") != -1){
			String[] split = administrativeLevel.split(",");
			ArrayList<String> arrayList = new ArrayList<>();
			Collections.addAll(arrayList, split);
			peopleInformation.setAdministrativeLevellist(arrayList);
		}else if(administrativeLevel != null && administrativeLevel.indexOf(",") == -1){
			String[] split = new String[]{administrativeLevel};
			ArrayList<String> arrayList = new ArrayList<>();
			Collections.addAll(arrayList, split);
			peopleInformation.setAdministrativeLevellist(arrayList);
		}
		if(twoInstitutionalName != null && twoInstitutionalName.indexOf(",") != -1){
			String[] split = twoInstitutionalName.split(",");
			ArrayList<String> arrayList = new ArrayList<>();
			Collections.addAll(arrayList, split);
			peopleInformation.setTwoInstitutionalNamelist(arrayList);
		}else if(twoInstitutionalName != null && twoInstitutionalName.indexOf(",") == -1){
			String[] split = new String[]{twoInstitutionalName};
			ArrayList<String> arrayList = new ArrayList<>();
			Collections.addAll(arrayList, split);
			peopleInformation.setTwoInstitutionalNamelist(arrayList);
		}
		if(jobNature != null && jobNature.indexOf(",") != -1){
			String[] split = jobNature.split(",");
			ArrayList<String> arrayList = new ArrayList<>();
			Collections.addAll(arrayList, split);
			peopleInformation.setJobNaturelist(arrayList);
		}else if(jobNature != null && jobNature.indexOf(",") == -1){
			String[] split = new String[]{jobNature};
			ArrayList<String> arrayList = new ArrayList<>();
			Collections.addAll(arrayList, split);
			peopleInformation.setJobNaturelist(arrayList);
		}
		if(identity != null && identity.indexOf(",") != -1){
			String[] splitss = identity.split(",");
			ArrayList<String> arrayssList = new ArrayList<>();
			Collections.addAll(arrayssList, splitss);
			peopleInformation.setIdentitylist(arrayssList);
		}else if(identity != null && identity.indexOf(",") == -1){
			String[] split = new String[]{identity};
			ArrayList<String> arrayssList = new ArrayList<>();
			Collections.addAll(arrayssList, split);
			peopleInformation.setIdentitylist(arrayssList);
		}
		page = super.findPage(page,peopleInformation);
		return page;
	}
	
	@Transactional(readOnly = false)
	public void save(PeopleInformation peopleInformation) {
		if (peopleInformation.getIsNewRecord()){
			peopleInformation.preInsert();
			mapper.insert(peopleInformation);
		}else{
			peopleInformation.preUpdate();
			mapper.update(peopleInformation);
		}
	}
	@Transactional(readOnly = false)
	public void normal(PeopleInformation peopleInformation) {
		mapper.normal(peopleInformation);
	}
	@Transactional(readOnly = false)
	public void updateAdministrativeLevel(String administrativeLevel,String oldAdministrativeLevel) {
		mapper.updateAdministrativeLevel(administrativeLevel,oldAdministrativeLevel);
	}

	@Transactional(readOnly = false)
	public void updateIdentity(String identity,String oldIdentity) {
		mapper.updateIdentity(identity,oldIdentity);
	}

	@Transactional(readOnly = false)
	public void updateJobNature(String jobNature,String oldJobNature){
		mapper.updateJobNature(jobNature,oldJobNature);
	}

	@Transactional(readOnly = false)
	public void updateOneInstitutional(String oneInstitutional,String oldOneInstitutional){
		mapper.updateOneInstitutional(oneInstitutional,oldOneInstitutional);
	}


	@Transactional(readOnly = false)
	public void delete(PeopleInformation peopleInformation) {
		super.delete(peopleInformation);
	}


}